package Processes;


import threadedSimulator.Cpu;

/**
 * runs a compute bound process.
 * @author Harris
 */
public class ComputeBoundProcess extends Processes{

    /**
     * storage for fibbinachi numbers computed.
     */
    private int[] my_nums = new int[MAX_VALUE];
	
	
    /**
     * constructor
     * @param the_cpu the cpu
     * @param the_numberof_pro_con  the number of producers and consumers
     */
    public ComputeBoundProcess(Cpu the_cpu, String the_numberof_pro_con) {
	super(the_cpu, the_numberof_pro_con, "ComputeBound");	
        my_priority = 3;
    }
        

    /**
     * runs the process.
     */
    public void run() {
        while (running && my_current_index <= MAX_VALUE) {//chdecks to make sure it is not halted
            running = true;
            my_current_index++;
            if (my_current_index == 0 || my_current_index == 1) {
            	my_nums[my_current_index] = 1;
            } else if (my_current_index == MAX_VALUE) { //resets the loop
            	//has_finished = true;
                my_current_index = 0;
                my_nums = new int[MAX_VALUE];
                running = false;
            } else {	//computes fibbinachi number
            	my_nums[my_current_index] = my_nums[my_current_index - 1] 
            								+ my_nums[my_current_index - 2];
            }
            

        }
    }
        

}
